package com.haipumi.biz.impl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.haipumi.beans.haipumi_activity;
import com.haipumi.beans.haipumi_skin;
import com.haipumi.beans.haipumi_user;
import com.haipumi.biz.IBackCustBiz;
import com.haipumi.dao.IBackCustDao;
import com.haipumi.dao.impl.BackCustDaoImpl;

public class BackCustBizImpl implements IBackCustBiz{
	
	
	IBackCustDao ibcd=new BackCustDaoImpl();
	
	@Override
	public List<haipumi_user> findCust(HttpServletRequest request) {
		String seacheroptions=null;
		seacheroptions=request.getParameter("searchOptions");
		String seacherType=request.getParameter("seacherType");
		List<haipumi_user>userlist=null;
		if(seacheroptions==""){
			//说明是初始化时候
			userlist=ibcd.findAllUser();
		}else{
			//查找的时候
			userlist=ibcd.seacherUser(request, seacherType);
		}
		return userlist;
	}

	@Override
	public int findusercount(HttpServletRequest request) {
		String seacherType=null;
		seacherType=request.getParameter("seacherType");
		String seacheroptions=request.getParameter("searchOptions");
		int r=0;
		if(seacheroptions==""){
			r=ibcd.findCount();
		}else{
			r=ibcd.findCount(request, seacherType);
		}
		return r;
	}

	@Override
	public haipumi_user insertCust(haipumi_user user) {
		
		haipumi_user backcust=ibcd.insertCust(user);
		return backcust;
	}

	@Override
	public haipumi_user updateUserImage(haipumi_user user) {
		boolean flag=false;
		flag=ibcd.updateUserImage(user);
		haipumi_user backuser=null;
		if(flag){
			//成功了
			backuser=ibcd.findUser(Integer.parseInt(user.getUid()));
			backuser.setUimage(user.getUimage());
		}else{
			//失败了，返回原先的值
			backuser=ibcd.findUser(Integer.parseInt(user.getUid()));
		}
		return backuser;
	}

	@Override
	public haipumi_user updateUser(haipumi_user user) {
		haipumi_user backuser=null;
		backuser=ibcd.updateUser(user);
		return backuser;
	}

	@Override
	public haipumi_skin updateSimage(haipumi_skin skin) {
		boolean flag=false;
		flag=ibcd.updatesimage(skin);
		haipumi_skin newskin=null;
		if(flag){
			//成功了
			newskin=ibcd.findskin(Integer.parseInt(skin.getSid()));
			newskin.setSimage(skin.getSimage());
		}else{
			//失败了，返回原先的值
			newskin=ibcd.findskin(Integer.parseInt(skin.getSid()));
		}
		return newskin;
	}

	@Override
	public haipumi_activity acphoto(haipumi_activity activity) {
		boolean flag=false;
		flag=ibcd.acphoto(activity);
		haipumi_activity newactivity=null;
		if(flag){
			//成功了
			newactivity=ibcd.findactivity(Integer.parseInt(activity.getAcid()));
			newactivity.setAcphoto(activity.getAcphoto());
		}else{
			//失败了，返回原先的值
			newactivity=ibcd.findactivity(Integer.parseInt(activity.getAcid()));
		}
		return newactivity;
	}

}
